package com.hliushi.spark.exmaple

import java.util.Properties

import org.apache.spark.sql.{DataFrame, SparkSession}
import org.junit.Test

/**
 * descriptions:
 *
 * author: Hliushi
 * date: 2021/5/30 15:18
 */
class SparkMysqlPractice {

  val url = "jdbc:mysql:///test?useSSL=false"
  val username = "root"
  val password = "root"
  val driver = "com.mysql.jdbc.Driver"

  val prop = new Properties()
  prop.setProperty("user", username)
  prop.setProperty("password", password)
  prop.setProperty("driver", driver)

  val spark: SparkSession = SparkSession.builder()
    .appName("mysql_50_spark")
    .master("local[6]")
    .getOrCreate()

  // 将四张表都创建对应的DataFrame
  val studentDF: DataFrame = spark.read.jdbc(url, "student", prop)
  val courseDF: DataFrame = spark.read.jdbc(url, "course", prop)
  val teacherDF: DataFrame = spark.read.jdbc(url, "teacher", prop)
  val scoreDF: DataFrame = spark.read.jdbc(url, "score", prop)


  // -- 1、查询"01"课程比"02"课程成绩高的学生的信息及课程分数
  @Test
  def test01(): Unit = {

  }
}